<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        arr=[2,4,7,3,8]
        let sum = 0
        let avg = 0
        function handleData(array,b){
            for(let i = 0;i<arr.length;i++){
                sum+=array[i]
                avg = (sum+=array[i])/array.length
                if(b===true || b === undefined){
                    return sum
                }else if(b === false){
                    return avg
                }
            }
        }
       console.log( handleData(arr,false));
    </script>
</body>
</html>